using System;
using System.Collections.Generic;
using Mall.Api.Entity;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Mall.Api.ParamModel;
using Newtonsoft.Json;
using Mall.Api.Repository;
using Mall.Api.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authorization;
using Mall.Api.Filters;

namespace Mall.Api.Controllers
{
    /// <summary>
    /// 商品添加时选择的仓库、商品属性和分类
    /// </summary>


    // [Authorize]

    [ApiController]
    [Route("commoodityadd")]
    public class CommodityAddController : ControllerBase
    {
        private IRepository<Class> _class;
        private IRepository<CommodityProperty> _commodityProperty;
        private IRepository<Warehouse> _warehouse;

        private readonly IConfiguration _configuration;

        public CommodityAddController(IConfiguration configuration, IRepository<Class> classes,IRepository<CommodityProperty> commodityProperty,IRepository<Warehouse> warehouse)
        {
            _configuration = configuration;
            _class = classes;
            _commodityProperty=commodityProperty;
            _warehouse =warehouse;
        }

        /// <summary>
        /// 获取分类列表
        /// </summary>
        /// 
        /// <returns></returns>
        [HttpGet("class")]
        public dynamic Get()
        {
            // 获得所有满足条件的记录
            var classes = _class.Table.Where(x => x.IsDeleted == false);
          
            var res = new
            {
                Code = 1000,
                Data = classes,
                Msg = "获取分类列表成功^_^"
            };
            return res;
        }




        /// <summary>
        /// 获取所有商品属性
        /// </summary>
        /// <returns></returns>

        [HttpGet("property")]
        public dynamic GetProperty()
        {
            // 获得所有满足条件的记录
            var commodityProperty = _commodityProperty.Table.Where(x => x.IsDeleted == false);
          
            var res = new
            {
                Code = 1000,
                Data = commodityProperty,
                Msg = "获取商品属性列表成功^_^"
            };
            return res;
        }





        /// <summary>
        /// 获取所有仓库
        /// </summary>
        /// <returns></returns>
        [HttpGet("warehouse")]
        public dynamic GetWarehouse()
        {
            // 获得所有满足条件的记录
            var warehouses = _warehouse.Table.Where(x => x.IsDeleted == false);
          
            var res = new
            {
                Code = 1000,
                Data = warehouses,
                Msg = "获取所有仓库成功^_^"
            };
            return res;
        }






    }
    
    }